﻿using IBll;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model;
using Microsoft.AspNetCore.StaticFiles;
using NPOI.XSSF.UserModel;

namespace WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class StarePteaController : ControllerBase, IStarePteabLL
    {
      
         public StarePteaController(IStarePteabLL bll,ILogger<StarePteaController> logger)
        {
            Bll = bll;
            Logger = logger;
        }
           
        public IStarePteabLL Bll { get; }
        public ILogger<StarePteaController> Logger { get; }

        /// <summary>
        /// 新增房号信息
        /// </summary>
        /// <param name="starePtea">房号表添加数据</param>
        /// <returns>返回受影响行数</returns>
        /// 
        [HttpPost]
        public Task<int> AddAnyns(StarePtea starePtea)
        {
            try//异常处理
            {
                Logger.LogInformation($"添加{starePtea}信息");
                 return Bll.AddAnyns(starePtea);

            }
            catch (Exception)
            {

                throw;
            }
        }

        [HttpGet]
        public List<StarePtea> GetStarePteas()
        {
            return Bll.GetStarePteas(); 
        }

    
        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="id">主键id</param>
        /// <returns>通过id 获取一条信息</returns>
        /// 

        [HttpDelete]
        public Task<int> Isdelete(int id)
        {
            try//异常处理
            {
                return Bll.Isdelete(id);
            }
            catch (Exception)
            {
                Logger.LogError($"{Isdelete}报错了");

                throw;
            }
        
        }

        // public IActionResult Exep()
        //{
        //    var shee = Bll.GetStarePteas();
        //    XSSFWorkbook sheets = new XSSFWorkbook();
        //    var row = sheets.CloneSheet(0);


        
        //}

        /// <summary>
        /// 逻辑修改
        /// </summary>
        /// <param name="id">主键id</param>
        /// <returns>通过id 获取一条信息</returns>
        /// 
        [HttpGet]
        public Task<int> ISstate(int id)
        {
            try//异常处理
            {
                return Bll.ISstate(id);
            }
            catch (Exception)
            {
                Logger.LogError($"{ISstate}报错了");
                throw;
            }
        
        }



        /// <summary>
        /// 查询显示
        /// </summary>
        /// <param name="name">房号名称</param>
        /// <param name="starePteaDate">创建时间</param>
        /// <param name="index">页数</param>
        /// <param name="size">条数</param>
        /// <returns>通过房号名称房号名称页数条数查询一条数</returns>

        [HttpGet]
        public dynamic ShowStarePtea(string? name, DateTime? starePteaDate, DateTime? endStarePtea)
        {
            try//异常处理
            {
                return Bll.ShowStarePtea(name, starePteaDate, endStarePtea);


            }
            catch (Exception)
            {

                throw;
            }

        }


    }
}
